﻿<?php

	// 管理员添加
	//加载初始化文件

	if(!empty($_POST)){//用来检测是否做了提交操作

		//多图片上传
		$savePath='';
		//$savePath[0]='';
		if (!empty($_FILES['file']['name'][0])) {
			$filelist=array();
			//数组重组
			foreach ($_FILES['file']['name'] as $key => $v) {
				//$filelist[$key]['name']=$v;或者
				$filelist[$key]['name']=$_FILES['file']['name'][$key];
				$filelist[$key]['type']=$_FILES['file']['type'][$key];
				$filelist[$key]['tmp_name']=$_FILES['file']['tmp_name'][$key];
				$filelist[$key]['error']=$_FILES['file']['error'][$key];
				$filelist[$key]['size']=$_FILES['file']['size'][$key];
			}
			foreach ($filelist as $value) {
				$savePath[]=uploads($value);
			}
		}

		//調用封裝:添加
		$data=$_POST;
		if(!empty($data['selects'])){unset($data['selects']);}//防止将下拉列表也提交了
		$data['create_time']=date('Y-m-d H:m:s',time());
		$data['login_time']=date('Y-m-d H:m:s',time());
		$data['out_time']=date('Y-m-d H:m:s',time());
		$data['pic']=$savePath[0];
		$_rows=add('admin',$data);

 // echo $_rows;die;
		if ($_rows>0) {
			echo '<script>alert("数据添加成功");location.href="index.php?c=admin&a=list&admin=1";</script>';
		}else
		{
			echo '<script>alert("数据添加失败");history.go(-1);</script>';die;
		}

	}

	//第一步：先查询角色
	$role=getSelect('role');

 	//加载后台公共视图
	include (VIEW_PATH.$admin.'layout.html');

 ?>

